package com.ymatou.riskcontrol.api.testcase;

import java.math.BigDecimal;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.riskcontrol.api.parameter.RiskRechargeBean;
import com.ymatou.riskcontrol.api.service.RiskRechargeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.RiskCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 风控充值接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_RiskRecharge {
	private static RiskRechargeBean rrb;
	private static RiskRechargeCall rrc;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("风控充值接口");
	}

	@Before
	public void caseUp() {
		rrb = new RiskRechargeBean();
		rrc = new RiskRechargeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(rrc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RiskRecharge_001() {
		Logger.start(true,"风控充值校验成功");
		try {
			// Map m = new OrderCallService().appSaveOrder();
			// Logger.debug("AppSaveOrder map:"+m);
			// int orderid = Integer.valueOf(m.get("OrderId").toString());
			// int userid = Integer.valueOf(m.get("UserId").toString());
			// int activityId= Integer.valueOf(m.get("ActivityId").toString());
			// int SellerId=Integer.valueOf(m.get("SellerId").toString());
			// int
			// ThirdCategoryId=Integer.valueOf(m.get("ThirdCategoryId").toString());
			// BigDecimal TotalPrice=new
			// BigDecimal(m.get("TotalPrice").toString());
			String orderid = TestDataManager.getClientpaymentId().substring(5, 13);
			String TraceId = TestDataManager.getRandomUUID().toString();
			rrb.setAppId("AppId");
			rrb.setOrderId(String.valueOf(orderid));
			String ExternalUserId = "EUID" + TestDataManager.getRandomNumToHex(5);
			rrb.setExternalUserId(ExternalUserId);
			String InternalUserId = "IUID" + TestDataManager.getRandomNumToHex(5);
			rrb.setInternalUserId(InternalUserId);
			rrb.setBizCode(200000);
			String InstPaymentId = "IPID" + TestDataManager.getRandomNumToHex(5);
			rrb.setInstPaymentId(InstPaymentId);
			String PaymentId = "PID" + TestDataManager.getRandomNumToHex(5);
			rrb.setPaymentId(PaymentId);
			BigDecimal PayPrice = new BigDecimal(10);
			rrb.setPayPrice(PayPrice);
			rrb.setTraceId(TraceId);
			rrc.setData(rrb);
			rrc.callService();
			Logger.comment("RiskRechargeCall send:" + rrc.getEntityString());
			Logger.comment("RiskRechargeCall return:" + rrc.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, rrc.getCode(), "验证Code");
			Logger.verifyEquals(ECode.SUCCESSMSG3, rrc.getMsg(), "验证Msg");
			
			JSONObject json = RiskCallService.getRiskDetail(String.valueOf(orderid));
			// 验证OrderId
			Logger.verifyEquals(orderid, json.get("OrderId"), "验证orderid");
			/**
			 * db.getCollection('UserEntity').find({}) 数据保存在mongodb
			 * 172.16.100.155 27019 RiskControlDB
			 * 
			 * 
			 * { "_id" :
			 * "PayId-df05c997-ef25-4e34-af12-db104f346b3a-c46ef88b-6b3a-401f-8645-6721089b4364-158263060"
			 * , "UserType" : 1, "UserKey" :
			 * "df05c997-ef25-4e34-af12-db104f346b3a-c46ef88b-6b3a-401f-8645-6721089b4364"
			 * , "UserId" : 1.58263e+008, "LastUpdateTime" :
			 * ISODate("2015-08-10T03:22:53.535Z") }
			 */
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_RiskRecharge_002() {
		Logger.start(true,"不输入必填项InternalUserId失败");
		try {
			String orderid = TestDataManager.getClientpaymentId().substring(5, 13);
			String TraceId = TestDataManager.getRandomUUID().toString();
			rrb.setAppId("AppId");
			rrb.setOrderId(String.valueOf(orderid));
			String ExternalUserId = "EUID" + TestDataManager.getRandomNumToHex(5);
			rrb.setExternalUserId(ExternalUserId);
			// String
			// InternalUserId="IUID"+TestDataManager.getRandomNumToHex(5);
			// rrb.setInternalUserId(InternalUserId);
			rrb.setBizCode(200000);
			String InstPaymentId = "IPID" + TestDataManager.getRandomNumToHex(5);
			rrb.setInstPaymentId(InstPaymentId);
			String PaymentId = "PID" + TestDataManager.getRandomNumToHex(5);
			rrb.setPaymentId(PaymentId);
			BigDecimal PayPrice = new BigDecimal(10);
			rrb.setPayPrice(PayPrice);
			rrb.setTraceId(TraceId);
			rrc.setData(rrb);
			rrc.callService();
			Logger.comment("RiskRechargeCall send:" + rrc.getEntityString());
			Logger.comment("RiskRechargeCall return:" + rrc.getReturnData());
			Logger.verifyEquals(ECode.ERROR500, rrc.getCode(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_RiskRecharge_003() {
		Logger.start(true,"不输入必填项ExternalUserId失败");
		try {
			String orderid = TestDataManager.getClientpaymentId().substring(5, 13);
			String TraceId = TestDataManager.getRandomUUID().toString();
			rrb.setAppId("AppId");
			rrb.setOrderId(String.valueOf(orderid));
			// String
			// ExternalUserId="EUID"+TestDataManager.getRandomNumToHex(5);
			// rrb.setExternalUserId(ExternalUserId);
			String InternalUserId = "IUID" + TestDataManager.getRandomNumToHex(5);
			rrb.setInternalUserId(InternalUserId);
			rrb.setBizCode(200000);
			String InstPaymentId = "IPID" + TestDataManager.getRandomNumToHex(5);
			rrb.setInstPaymentId(InstPaymentId);
			String PaymentId = "PID" + TestDataManager.getRandomNumToHex(5);
			rrb.setPaymentId(PaymentId);
			BigDecimal PayPrice = new BigDecimal(10);
			rrb.setPayPrice(PayPrice);
			rrb.setTraceId(TraceId);
			rrc.setData(rrb);
			rrc.callService();
			Logger.comment("RiskRechargeCall send:" + rrc.getEntityString());
			Logger.comment("RiskRechargeCall return:" + rrc.getReturnData());
			Logger.verifyEquals(ECode.ERROR500, rrc.getCode(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}